package com.yyfax.ph.personal.feedback;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class FeedBackModel extends Model {
	private static final String TAG = FeedBackModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		FeedBackModel.Service service = (FeedBackModel.Service) NetworkHelper.createService(FeedBackModel.Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.feedBack(token, new FeedBackContent((String) params));
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		FeedBackResult baseResultEntity = (FeedBackResult) obj;
		EventAgent.post(baseResultEntity);
	}

	public interface Service{
		@POST("sys/feedback/report")
		Observable<FeedBackResult> feedBack(@Header("token") String token, @Body FeedBackContent content);
	}
	protected static class FeedBackContent {
		String content;

		public FeedBackContent(String content) {
			this.content = content;
		}
	}

	class FeedBackResult extends BaseResultEntity{}


}
